﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLNHASACH.PresentationLayer.SearchCtrl
{
    public partial class ListBoxKH : UserControl
    {
        public ListBoxKH()
        {
            InitializeComponent();
        }

        public delegate void sukien();
        public event sukien ItemClick;

        public ItemKH SelectedItem=new ItemKH();

        public List<ItemKH> Items=new List<ItemKH>();
        private DataTable _datasource;
        public DataTable Datasource
        {
            set
            {
                _datasource = value;
                this.Controls.Clear();
                Items.Clear();
                if (_datasource != null)
                {
                    foreach (DataRow row in _datasource.Rows)
                    {
                        ItemKH item=new ItemKH();
                        item.Clik += new ItemKH.sukien(item_Clik);
                        item.SetData(row);
                        this.Controls.Add(item);
                        item.Dock = DockStyle.Top;
                        Items.Add(item);
                    }
                }
            }
            get
            {
                return _datasource;
            }
        }
        void item_Clik(object sender)
        {
            SelectedItem = (ItemKH)sender;
            if (ItemClick != null)
                ItemClick();
        }
    }
}
